/**
 * 
 */
package com.disys.facade;

import java.io.Serializable;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

import com.disys.dao.ProcessDAO;
import com.disys.model.Process;
import com.disys.model.Rec140ERWOTCLOC;

/**
 * @author Ubaid Raja
 * 
 */
public class ProcessFacade implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private ProcessDAO obj = new ProcessDAO();

	public Integer insertProcessRecord(Process entity) {
		obj.beginTransaction();
		// entity = obj.update(entity);
		obj.save(entity);
		obj.commit();
		// obj.commitAndCloseTransaction();
		return entity.getId();
	}

	public List<Process> findAllProcesses() {
		List<Process> list = null;
		try {
			obj.beginTransaction();
			list = obj.findAllSorted("Process");
			obj.closeTransaction();
		} catch (IllegalStateException ex) {
			list = obj.findAllSorted("Process");
			obj.closeTransaction();
		}
		if (list.size() == 0 || list == null) {
			return new ArrayList<Process>();
		}
		return list;
	}

	public Process findSingleProcess(Integer entityID) {
		obj.beginTransaction();
		Process object = obj.find(entityID);
		obj.closeTransaction();
		return object;
	}

	public void updateProcess(Process entity) {
		try {
			obj.beginTransaction();
			obj.update(entity);
			obj.commit();
		} catch (IllegalStateException e) {

		}

	}

	public void finalizeRecords(String object, Integer isFinalized,BigInteger processId) {
		obj.beginTransaction();
		obj.finalizeRecords(object, isFinalized, processId);
		obj.commit();
	}

	public Process getLastFinalizedProcess(String object) {
		obj.beginTransaction();
		Process ob = obj.getLastFinalizedProcess(object);
		obj.commit();
		return ob;
	}
	
	public List<Integer> getAllProcessIds(String object) {
		obj.beginTransaction();
		List<Integer> list = obj.getAllProcessIds(object);
		obj.closeTransaction();
		return list;
	}
	
	public List<Integer> getFinalizeProcessOfAWeek(String object,Integer week){
		obj.beginTransaction();
		List<Integer> list = obj.getFinalizeProcessOfAWeek(object,week);
		obj.closeTransaction();
		return list;
	}
}
